package com.wigem.approve.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wigem.approve.mapper.DaqEstateMapper;
import com.wigem.framework.common.pojo.PageResult;
import com.wigem.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.wigem.approve.entity.GeApproveLogEntity;
import com.wigem.approve.mapper.GeApproveLogMapper;
import com.wigem.approve.vo.GeApproveLogVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * 【审批日志】Service业务层处理
 *
 * @author YMY
 * @date 2023-08-09
 */
@Service
public class GeApproveLogServiceImpl implements GeApproveLogService {

    @Resource
    private GeApproveLogMapper geApproveLogMapper;


    @Override
    public List<GeApproveLogEntity> getList(GeApproveLogVo geApproveLogvo) {

        return geApproveLogMapper.selectList(query(geApproveLogvo));
    }

    @Override
    public PageResult<GeApproveLogEntity> getPageList(GeApproveLogVo geApproveLogVo) {
        Page<GeApproveLogEntity> page = new Page<>(geApproveLogVo.getPageNo(), geApproveLogVo.getPageSize());
        IPage<GeApproveLogEntity> mappingList = geApproveLogMapper.getPageList(page, geApproveLogVo);
        return new PageResult<>(mappingList.getRecords(), mappingList.getTotal());
    }


    @Override
    public GeApproveLogEntity getEntity(String id) {
        return geApproveLogMapper.selectById(id);
    }

    @Override
    public void add(GeApproveLogVo geApproveLogVo) {
        GeApproveLogEntity geApproveLogEntity = new GeApproveLogEntity();
        BeanUtils.copyProperties(geApproveLogVo, geApproveLogEntity);
        geApproveLogEntity.create();
        geApproveLogMapper.insert(geApproveLogEntity);
    }


    @Override
    public void update(GeApproveLogVo geApproveLogVo) {
        GeApproveLogEntity geApproveLogEntity = new GeApproveLogEntity();
        BeanUtils.copyProperties(geApproveLogVo, geApproveLogEntity);
        geApproveLogMapper.updateById(geApproveLogEntity);
    }

    @Override
    public void save(GeApproveLogVo geApproveLogVo) {

        GeApproveLogEntity geApproveLogEntity = new GeApproveLogEntity();
        BeanUtils.copyProperties(geApproveLogVo, geApproveLogEntity);
        if (StringUtils.isEmpty(geApproveLogVo.getId())) {
            geApproveLogEntity.create();
            geApproveLogMapper.insert(geApproveLogEntity);
        } else {
            geApproveLogMapper.updateById(geApproveLogEntity);
        }

    }


    @Override
    public int delete(String id) {
        return geApproveLogMapper.deleteById(id);
    }


    @Override
    public int remove(String id) {
        return geApproveLogMapper.remove(id);
    }


    public LambdaQueryWrapperX<GeApproveLogEntity> query(GeApproveLogVo geApproveLogVo) {

        LambdaQueryWrapperX<GeApproveLogEntity> geApproveLogEntityLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        geApproveLogEntityLambdaQueryWrapperX = geApproveLogEntityLambdaQueryWrapperX
                .eqIfPresent(GeApproveLogEntity::getId, geApproveLogVo.getId())
                .eqIfPresent(GeApproveLogEntity::getUserId, geApproveLogVo.getUserId())
                .eqIfPresent(GeApproveLogEntity::getUserUnit, geApproveLogVo.getUserUnit())
                .likeIfPresent(GeApproveLogEntity::getRealName, geApproveLogVo.getRealName())
                .eqIfPresent(GeApproveLogEntity::getOperateInfoId, geApproveLogVo.getOperateInfoId())
                .likeIfPresent(GeApproveLogEntity::getOperateProcessName, geApproveLogVo.getOperateProcessName())
                .eqIfPresent(GeApproveLogEntity::getOperateContent, geApproveLogVo.getOperateContent())
                .eqIfPresent(GeApproveLogEntity::getOperateTime, geApproveLogVo.getOperateTime())
                .eqIfPresent(GeApproveLogEntity::getOperateReason, geApproveLogVo.getOperateReason())

        ;
        return geApproveLogEntityLambdaQueryWrapperX;
    }


}
